package com.liyong.bos.controller;

import com.liyong.bos.domain.AuthFunction;
import com.liyong.bos.service.MenuService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by ApacheMoy on 2017/4/9.
 */
@Controller
@RequestMapping(value = "/menus")
public class MenuJsonController {
    @Autowired
    private MenuService menuService;
    @RequestMapping(value = "/leftTree")
    public  @ResponseBody  List<AuthFunction> getLeftTreeMenu(){
        List<AuthFunction> list=menuService.getLeftTreeMenu();
        for(AuthFunction authFunction:list){
            if(!StringUtils.isNotBlank(authFunction.getPid())){
                authFunction.setPid("0");
            }
        }
        return list;
        /*String first="[";
        String str="";
        String end="]";
        for(AuthFunction authFunction:list){

            if(!StringUtils.isNotBlank(authFunction.getPage())){
                str+="{\"id\":\""+authFunction.getId()+"\",\"pid\":\"" + authFunction.getPid() + "\",\"name\":\"" + authFunction.getName() + "\"},";
            }else {
                str+="{\"id\":\""+authFunction.getId()+"\",\"pid\":\"" + authFunction.getPid() + "\",\"name\":\"" + authFunction.getName() + "\",\"page\":\"" + authFunction.getPage() + "\"},";
            }
        }
        System.out.println("-------------");
        System.out.println(first+str+end);
        System.out.println("-------------");*/
    }
}
